home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Interfaces&Libraries / Universal / Interfaces / CIncludes / DateTimeUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  12.7 KB  |  444 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        DateTimeUtils.h
  3.  
  4.      Contains:    International Date and Time Interfaces (previously in TextUtils)
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __DATETIMEUTILS__
  18. #define __DATETIMEUTILS__
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21. #include <ConditionalMacros.h>
  22. #endif
  23. #ifndef __MACTYPES__
  24. #include <MacTypes.h>
  25. #endif
  26.  
  27.  
  28.  
  29. #if PRAGMA_ONCE
  30. #pragma once
  31. #endif
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36.  
  37. #if PRAGMA_IMPORT
  38. #pragma import on
  39. #endif
  40.  
  41. #if PRAGMA_STRUCT_ALIGN
  42.     #pragma options align=mac68k
  43. #elif PRAGMA_STRUCT_PACKPUSH
  44.     #pragma pack(push, 2)
  45. #elif PRAGMA_STRUCT_PACK
  46.     #pragma pack(2)
  47. #endif
  48.  
  49. /*
  50.  
  51.     Here are the current routine names and the translations to the older forms.
  52.     Please use the newer forms in all new code and migrate the older names out of existing
  53.     code as maintainance permits.
  54.     
  55.     New Name                    Old Name(s)
  56.     
  57.     DateString                    IUDatePString IUDateString 
  58.     InitDateCache
  59.     LongDateString                IULDateString
  60.     LongTimeString                IULTimeString
  61.     StringToDate                String2Date
  62.     StringToTime                                
  63.     TimeString                    IUTimeString IUTimePString
  64.     LongDateToSeconds            LongDate2Secs
  65.     LongSecondsToDate            LongSecs2Date
  66.     DateToSeconds                Date2Secs
  67.     SecondsToDate                Secs2Date
  68. */
  69.  
  70.  
  71. enum {
  72.                                                                 /* Toggle results */
  73.     toggleUndefined                = 0,
  74.     toggleOK                    = 1,
  75.     toggleBadField                = 2,
  76.     toggleBadDelta                = 3,
  77.     toggleBadChar                = 4,
  78.     toggleUnknown                = 5,
  79.     toggleBadNum                = 6,
  80.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  81.     toggleErr3                    = 7,
  82.     toggleErr4                    = 8,
  83.     toggleErr5                    = 9
  84. };
  85.  
  86.  
  87. enum {
  88.                                                                 /* Date equates */
  89.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  90.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  91.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  92.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  93.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  94.     validDateFields                = -1,
  95.     maxDateField                = 10
  96. };
  97.  
  98.  
  99. enum {
  100.     eraMask                        = 0x0001,
  101.     yearMask                    = 0x0002,
  102.     monthMask                    = 0x0004,
  103.     dayMask                        = 0x0008,
  104.     hourMask                    = 0x0010,
  105.     minuteMask                    = 0x0020,
  106.     secondMask                    = 0x0040,
  107.     dayOfWeekMask                = 0x0080,
  108.     dayOfYearMask                = 0x0100,
  109.     weekOfYearMask                = 0x0200,
  110.     pmMask                        = 0x0400,
  111.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  112. };
  113.  
  114.  
  115. enum {
  116.     eraField                    = 0,
  117.     yearField                    = 1,
  118.     monthField                    = 2,
  119.     dayField                    = 3,
  120.     hourField                    = 4,
  121.     minuteField                    = 5,
  122.     secondField                    = 6,
  123.     dayOfWeekField                = 7,
  124.     dayOfYearField                = 8,
  125.     weekOfYearField                = 9,
  126.     pmField                        = 10,
  127.     res1Field                    = 11,
  128.     res2Field                    = 12,
  129.     res3Field                    = 13
  130. };
  131.  
  132. typedef SignedByte                         LongDateField;
  133.  
  134. enum {
  135.     shortDate                    = 0,
  136.     longDate                    = 1,
  137.     abbrevDate                    = 2
  138. };
  139.  
  140. typedef SInt8                             DateForm;
  141.  
  142. enum {
  143.                                                                 /* StringToDate status values */
  144.     fatalDateTime                = 0x8000,                        /* StringToDate and String2Time mask to a fatal error */
  145.     longDateFound                = 1,                            /* StringToDate mask to long date found */
  146.     leftOverChars                = 2,                            /* StringToDate & Time mask to warn of left over characters */
  147.     sepNotIntlSep                = 4,                            /* StringToDate & Time mask to warn of non-standard separators */
  148.     fieldOrderNotIntl            = 8,                            /* StringToDate & Time mask to warn of non-standard field order */
  149.     extraneousStrings            = 16,                            /* StringToDate & Time mask to warn of unparsable strings in text */
  150.     tooManySeps                    = 32,                            /* StringToDate & Time mask to warn of too many separators */
  151.     sepNotConsistent            = 64,                            /* StringToDate & Time mask to warn of inconsistent separators */
  152.     tokenErr                    = 0x8100,                        /* StringToDate & Time mask for 'tokenizer err encountered' */
  153.     cantReadUtilities            = 0x8200,
  154.     dateTimeNotFound            = 0x8400,
  155.     dateTimeInvalid                = 0x8800
  156. };
  157.  
  158. typedef short                             StringToDateStatus;
  159. typedef short                             String2DateStatus;
  160.  
  161. struct DateCacheRecord {
  162.     short                             hidden[256];                /* only for temporary use */
  163. };
  164. typedef struct DateCacheRecord            DateCacheRecord;
  165.  
  166. typedef DateCacheRecord *                DateCachePtr;
  167.  
  168. struct DateTimeRec {
  169.     short                             year;
  170.     short                             month;
  171.     short                             day;
  172.     short                             hour;
  173.     short                             minute;
  174.     short                             second;
  175.     short                             dayOfWeek;
  176. };
  177. typedef struct DateTimeRec                DateTimeRec;
  178.  
  179. typedef SInt64                             LongDateTime;
  180.  
  181. union LongDateCvt {
  182.     SInt64                             c;
  183.     struct {
  184.         UInt32                             lHigh;
  185.         UInt32                             lLow;
  186.     }                                 hl;
  187. };
  188. typedef union LongDateCvt                LongDateCvt;
  189.  
  190. union LongDateRec {
  191.     struct {
  192.         short                             era;
  193.         short                             year;
  194.         short                             month;
  195.         short                             day;
  196.         short                             hour;
  197.         short                             minute;
  198.         short                             second;
  199.         short                             dayOfWeek;
  200.         short                             dayOfYear;
  201.         short                             weekOfYear;
  202.         short                             pm;
  203.         short                             res1;
  204.         short                             res2;
  205.         short                             res3;
  206.     }                                 ld;
  207.     short                             list[14];                    /*Index by LongDateField!*/
  208.     struct {
  209.         short                             eraAlt;
  210.         DateTimeRec                     oldDate;
  211.     }                                 od;
  212. };
  213. typedef union LongDateRec                LongDateRec;
  214.  
  215. typedef SInt8                             DateDelta;
  216.  
  217. struct TogglePB {
  218.     long                             togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  219.     ResType                         amChars;                    /*from 'itl0', but uppercased*/
  220.     ResType                         pmChars;                    /*from 'itl0', but uppercased*/
  221.     long                             reserved[4];
  222. };
  223. typedef struct TogglePB                    TogglePB;
  224.  
  225. typedef short                             ToggleResults;
  226. /*
  227.  **************************************************************************************
  228.  *
  229.  * The following functions are new names that work on 68k and PowerPC
  230.  *
  231.  **************************************************************************************
  232. */
  233.  
  234. EXTERN_API( OSErr )
  235. InitDateCache                    (DateCachePtr             theCache)                            FOURWORDINLINE(0x2F3C, 0x8204, 0xFFF8, 0xA8B5);
  236.  
  237. EXTERN_API( StringToDateStatus )
  238. StringToDate                    (Ptr                     textPtr,
  239.                                  long                     textLen,
  240.                                  DateCachePtr             theCache,
  241.                                  long *                    lengthUsed,
  242.                                  LongDateRec *            dateTime)                            FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF6, 0xA8B5);
  243.  
  244. EXTERN_API( StringToDateStatus )
  245. StringToTime                    (Ptr                     textPtr,
  246.                                  long                     textLen,
  247.                                  DateCachePtr             theCache,
  248.                                  long *                    lengthUsed,
  249.                                  LongDateRec *            dateTime)                            FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF4, 0xA8B5);
  250.  
  251. EXTERN_API( void )
  252. IUDateString                    (long                     dateTime,
  253.                                  DateForm                 longFlag,
  254.                                  Str255                 result)                                TWOWORDINLINE(0x4267, 0xA9ED);
  255.  
  256. EXTERN_API( void )
  257. IUTimeString                    (long                     dateTime,
  258.                                  Boolean                 wantSeconds,
  259.                                  Str255                 result)                                THREEWORDINLINE(0x3F3C, 0x0002, 0xA9ED);
  260.  
  261. EXTERN_API( void )
  262. IUDatePString                    (long                     dateTime,
  263.                                  DateForm                 longFlag,
  264.                                  Str255                 result,
  265.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x000E, 0xA9ED);
  266.  
  267. EXTERN_API( void )
  268. IUTimePString                    (long                     dateTime,
  269.                                  Boolean                 wantSeconds,
  270.                                  Str255                 result,
  271.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0010, 0xA9ED);
  272.  
  273. EXTERN_API( void )
  274. IULDateString                    (LongDateTime *            dateTime,
  275.                                  DateForm                 longFlag,
  276.                                  Str255                 result,
  277.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0014, 0xA9ED);
  278.  
  279. EXTERN_API( void )
  280. IULTimeString                    (LongDateTime *            dateTime,
  281.                                  Boolean                 wantSeconds,
  282.                                  Str255                 result,
  283.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0016, 0xA9ED);
  284.  
  285.  
  286. EXTERN_API( void )
  287. LongDateToSeconds                (const LongDateRec *    lDate,
  288.                                  LongDateTime *            lSecs)                                FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  289.  
  290. EXTERN_API( void )
  291. LongSecondsToDate                (const LongDateTime *    lSecs,
  292.                                  LongDateRec *            lDate)                                FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  293.  
  294. EXTERN_API( ToggleResults )
  295. ToggleDate                        (LongDateTime *            lSecs,
  296.                                  LongDateField             field,
  297.                                  DateDelta                 delta,
  298.                                  short                     ch,
  299.                                  const TogglePB *        params)                                FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  300.  
  301. EXTERN_API( short )
  302. ValidDate                        (const LongDateRec *    vDate,
  303.                                  long                     flags,
  304.                                  LongDateTime *            newSecs)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  305.  
  306.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  307.                                                                                             #pragma parameter __D0 ReadDateTime(__A0)
  308.                                                                                             #endif
  309. EXTERN_API( OSErr )
  310. ReadDateTime                    (unsigned long *        time)                                ONEWORDINLINE(0xA039);
  311.  
  312.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  313.                                                                                             #pragma parameter GetDateTime(__A0)
  314.                                                                                             #endif
  315. EXTERN_API( void )
  316. GetDateTime                        (unsigned long *        secs)                                TWOWORDINLINE(0x20B8, 0x020C);
  317.  
  318.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  319.                                                                                             #pragma parameter __D0 SetDateTime(__D0)
  320.                                                                                             #endif
  321. EXTERN_API( OSErr )
  322. SetDateTime                        (unsigned long             time)                                ONEWORDINLINE(0xA03A);
  323.  
  324.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  325.                                                                                             #pragma parameter SetTime(__A0)
  326.                                                                                             #endif
  327. EXTERN_API( void )
  328. SetTime                            (const DateTimeRec *    d)                                    TWOWORDINLINE(0xA9C7, 0xA03A);
  329.  
  330.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  331.                                                                                             #pragma parameter GetTime(__A0)
  332.                                                                                             #endif
  333. EXTERN_API( void )
  334. GetTime                            (DateTimeRec *            d)                                    THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  335.  
  336. EXTERN_API( void )
  337. DateToSeconds                    (const DateTimeRec *    d,
  338.                                  unsigned long *        secs);
  339.  
  340.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  341.                                                                                             #pragma parameter SecondsToDate(__D0, __A0)
  342.                                                                                             #endif
  343. EXTERN_API( void )
  344. SecondsToDate                    (unsigned long             secs,
  345.                                  DateTimeRec *            d)                                    ONEWORDINLINE(0xA9C6);
  346.  
  347. /*
  348.  **************************************************************************************
  349.  *
  350.  * The following are macros which map new names to the names exported by InterfaceLib
  351.  *
  352.  **************************************************************************************
  353. */
  354. #define DateString(dateTime, longFlag, result, intlHandle) \
  355.          IUDatePString( dateTime, longFlag, result, intlHandle)
  356. #define TimeString(dateTime, wantSeconds, result, intlHandle) \
  357.          IUTimePString(dateTime, wantSeconds, result, intlHandle)
  358. #define LongDateString(dateTime, longFlag, result, intlHandle) \
  359.          IULDateString(dateTime, longFlag, result, intlHandle)
  360. #define LongTimeString(dateTime, wantSeconds, result, intlHandle) \
  361.          IULTimeString(dateTime, wantSeconds, result, intlHandle)
  362.  
  363. /*
  364.  **************************************************************************************
  365.  *
  366.  * The following are macros which map old names to the names exported by InterfaceLib
  367.  *
  368.  **************************************************************************************
  369. */
  370. #if OLDROUTINENAMES
  371. #define String2Date(textPtr, textLen, theCache, lengthUsed, dateTime)  \
  372.          StringToDate(textPtr, textLen, theCache, lengthUsed, dateTime)
  373. #define String2Time(textPtr, textLen, theCache, lengthUsed, dateTime)  \
  374.          StringToTime(textPtr, textLen, theCache, lengthUsed, dateTime)
  375. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  376. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  377. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  378. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  379. #if CGLUESUPPORTED
  380. EXTERN_API_C( void )
  381. iudatestring                    (long                     dateTime,
  382.                                  DateForm                 longFlag,
  383.                                  char *                    result);
  384.  
  385. EXTERN_API_C( void )
  386. iudatepstring                    (long                     dateTime,
  387.                                  DateForm                 longFlag,
  388.                                  char *                    result,
  389.                                  Handle                 intlHandle);
  390.  
  391. EXTERN_API_C( void )
  392. iutimestring                    (long                     dateTime,
  393.                                  Boolean                 wantSeconds,
  394.                                  char *                    result);
  395.  
  396. EXTERN_API_C( void )
  397. iutimepstring                    (long                     dateTime,
  398.                                  Boolean                 wantSeconds,
  399.                                  char *                    result,
  400.                                  Handle                 intlHandle);
  401.  
  402. EXTERN_API_C( void )
  403. iuldatestring                    (LongDateTime *            dateTime,
  404.                                  DateForm                 longFlag,
  405.                                  char *                    result,
  406.                                  Handle                 intlHandle);
  407.  
  408. EXTERN_API_C( void )
  409. iultimestring                    (LongDateTime *            dateTime,
  410.                                  Boolean                 wantSeconds,
  411.                                  char *                    result,
  412.                                  Handle                 intlHandle);
  413.  
  414. #else
  415. #endif  /* CGLUESUPPORTED */
  416.  
  417. #endif  /* OLDROUTINENAMES */
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424. #if PRAGMA_STRUCT_ALIGN
  425.     #pragma options align=reset
  426. #elif PRAGMA_STRUCT_PACKPUSH
  427.     #pragma pack(pop)
  428. #elif PRAGMA_STRUCT_PACK
  429.     #pragma pack()
  430. #endif
  431.  
  432. #ifdef PRAGMA_IMPORT_OFF
  433. #pragma import off
  434. #elif PRAGMA_IMPORT
  435. #pragma import reset
  436. #endif
  437.  
  438. #ifdef __cplusplus
  439. }
  440. #endif
  441.  
  442. #endif /* __DATETIMEUTILS__ */
  443.  
  444.